package com.nowcoder.chafen;

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		long[] p = new long[n + 2];
		long[] b = new long[n + 2];
		
		for (int i = 1; i <= n; i ++) {
			p[i] = scanner.nextLong();
			b[i] = p[i] - p[i-1];
		}
		long ans1 = 0, ans2 = 0;
		for (int i = 2; i <= n; i ++) {
			if (b[i] >= 0) {
				ans1 += b[i];
			} else {
				ans2 += -b[i];
			}
		}
		System.out.println(Math.max(ans1, ans2));
	
	}
}
